/**
 * Created by webhugo on 16-10-16.
 */
var sequelizex = require('sequelize-short');
var shortDataTypes = sequelizex.DataTypes;
module.exports = function (sequelize, DataTypes) {
    var Course = sequelize.define('Course', {
        title: shortDataTypes.String(undefined, undefined, undefined, true),
        difficulty: shortDataTypes.Int(),//1 是简单, 2 是中级, 3是困难
        description: shortDataTypes.Text(),//课程描述,即简介
        score: shortDataTypes.Int(0),//综合评分
        chapter: shortDataTypes.Int(),//章节数量
        starNum: shortDataTypes.Int(0),//点赞人数
        followNum: shortDataTypes.Int(0),//关注人数,
        participantCount: shortDataTypes.Int(0),//当前学习人数
        teacher: shortDataTypes.String(),
        cover: shortDataTypes.String(),//封面图片
        size: shortDataTypes.Int(0),
        location: shortDataTypes.String(),//该视频存放位置
        major : shortDataTypes.String() // 所属方向
    }, {
        associate: function (models) {
            models.Course.hasMany(models.Chapter);
            models.Chapter.belongsTo(models.Course);
            models.Course.hasMany(models.Comment);
            models.Comment.belongsTo(models.Course);

            models.Course.hasMany(models.Comment);
            models.Comment.belongsTo(models.Course);
            // models.Course.belongsToMany(models.User, {through: 'UserCourse'});
        },
        instanceMethods: {}
    });

    return Course;
};
